package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()
	router.POST("/valid", PostValidData)
	router.Run()
}

//绑定form和query和json可以使用form
/*
binding:"required" 不能为空
*/
type Article struct {
	Id      int    `form:"-"`//表示不做验证
	Title   string `form:"title" binding:"required"`//不能为空
	Content string `form:"content" binding:"required"`
	Desc    string `form:"desc" binding:"required"`
}

func PostValidData(ctx *gin.Context) {
	var article Article
	ctx.ShouldBind(&article)
	fmt.Println(article)
	ctx.String(http.StatusOK,"数据验证成功")
	return
}